<?php

/**
 * Business.
 *
 * PHP version 8.3
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * The Selling Partner API for Sellers.
 *
 * The [Selling Partner API for Sellers](https://developer-docs.amazon.com/sp-api/docs/sellers-api-v1-reference) (Sellers API) provides essential information about seller accounts, such as:  - The marketplaces a seller can list in - The default language and currency of a marketplace - Whether the seller has suspended listings  Refer to the [Sellers API reference](https://developer-docs.amazon.com/sp-api/docs/sellers-api-v1-reference) for details about this API's operations, data types, and schemas.
 *
 * The version of the OpenAPI document: v1
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Model\sellers\v1;

use SpApi\Model\ModelInterface;
use SpApi\ObjectSerializer;

/**
 * Business Class Doc Comment.
 *
 * @category Class
 *
 * @description Information about the seller&#39;s business. Certain fields may be omitted depending on the seller&#39;s &#x60;businessType&#x60;.
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class Business implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    /**
     * The original name of the model.
     */
    protected static string $openAPIModelName = 'Business';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static array $openAPITypes = [
        'name' => 'string',
        'registered_business_address' => '\SpApi\Model\sellers\v1\Address',
        'company_registration_number' => 'string',
        'company_tax_identification_number' => 'string',
        'non_latin_name' => 'string'];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static array $openAPIFormats = [
        'name' => null,
        'registered_business_address' => null,
        'company_registration_number' => null,
        'company_tax_identification_number' => null,
        'non_latin_name' => null];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'name' => false,
        'registered_business_address' => false,
        'company_registration_number' => true,
        'company_tax_identification_number' => true,
        'non_latin_name' => true,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static array $attributeMap = [
        'name' => 'name',
        'registered_business_address' => 'registeredBusinessAddress',
        'company_registration_number' => 'companyRegistrationNumber',
        'company_tax_identification_number' => 'companyTaxIdentificationNumber',
        'non_latin_name' => 'nonLatinName',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static array $setters = [
        'name' => 'setName',
        'registered_business_address' => 'setRegisteredBusinessAddress',
        'company_registration_number' => 'setCompanyRegistrationNumber',
        'company_tax_identification_number' => 'setCompanyTaxIdentificationNumber',
        'non_latin_name' => 'setNonLatinName',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static array $getters = [
        'name' => 'getName',
        'registered_business_address' => 'getRegisteredBusinessAddress',
        'company_registration_number' => 'getCompanyRegistrationNumber',
        'company_tax_identification_number' => 'getCompanyTaxIdentificationNumber',
        'non_latin_name' => 'getNonLatinName',
    ];

    /**
     * Associative array for storing property values.
     */
    protected array $container = [];

    /**
     * Constructor.
     *
     * @param null|array $data Associated array of property values
     *                         initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('name', $data ?? [], null);
        $this->setIfExists('registered_business_address', $data ?? [], null);
        $this->setIfExists('company_registration_number', $data ?? [], null);
        $this->setIfExists('company_tax_identification_number', $data ?? [], null);
        $this->setIfExists('non_latin_name', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        if (null === $this->container['name']) {
            $invalidProperties[] = "'name' can't be null";
        }
        if (null === $this->container['registered_business_address']) {
            $invalidProperties[] = "'registered_business_address' can't be null";
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets name.
     */
    public function getName(): string
    {
        return $this->container['name'];
    }

    /**
     * Sets name.
     *
     * @param string $name the registered business name
     */
    public function setName(string $name): self
    {
        if (is_null($name)) {
            throw new \InvalidArgumentException('non-nullable name cannot be null');
        }
        $this->container['name'] = $name;

        return $this;
    }

    /**
     * Gets registered_business_address.
     */
    public function getRegisteredBusinessAddress(): Address
    {
        return $this->container['registered_business_address'];
    }

    /**
     * Sets registered_business_address.
     *
     * @param Address $registered_business_address registered_business_address
     */
    public function setRegisteredBusinessAddress(Address $registered_business_address): self
    {
        if (is_null($registered_business_address)) {
            throw new \InvalidArgumentException('non-nullable registered_business_address cannot be null');
        }
        $this->container['registered_business_address'] = $registered_business_address;

        return $this;
    }

    /**
     * Gets company_registration_number.
     */
    public function getCompanyRegistrationNumber(): ?string
    {
        return $this->container['company_registration_number'];
    }

    /**
     * Sets company_registration_number.
     *
     * @param null|string $company_registration_number The seller's company registration number, if applicable. This field will be absent for individual sellers and sole proprietorships.
     */
    public function setCompanyRegistrationNumber(?string $company_registration_number): self
    {
        if (is_null($company_registration_number)) {
            array_push($this->openAPINullablesSetToNull, 'company_registration_number');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('company_registration_number', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['company_registration_number'] = $company_registration_number;

        return $this;
    }

    /**
     * Gets company_tax_identification_number.
     */
    public function getCompanyTaxIdentificationNumber(): ?string
    {
        return $this->container['company_tax_identification_number'];
    }

    /**
     * Sets company_tax_identification_number.
     *
     * @param null|string $company_tax_identification_number The seller's company tax identification number, if applicable. This field will be present for certain business types only, such as sole proprietorships.
     */
    public function setCompanyTaxIdentificationNumber(?string $company_tax_identification_number): self
    {
        if (is_null($company_tax_identification_number)) {
            array_push($this->openAPINullablesSetToNull, 'company_tax_identification_number');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('company_tax_identification_number', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['company_tax_identification_number'] = $company_tax_identification_number;

        return $this;
    }

    /**
     * Gets non_latin_name.
     */
    public function getNonLatinName(): ?string
    {
        return $this->container['non_latin_name'];
    }

    /**
     * Sets non_latin_name.
     *
     * @param null|string $non_latin_name the non-Latin script version of the registered business name, if applicable
     */
    public function setNonLatinName(?string $non_latin_name): self
    {
        if (is_null($non_latin_name)) {
            array_push($this->openAPINullablesSetToNull, 'non_latin_name');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('non_latin_name', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['non_latin_name'] = $non_latin_name;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, mixed $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     *               of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
